{******************************************************************************}
{                                                                              }
{                            Dialog-Vorlage                                    }
{                                                                              }
{                    Copyright (c) 2005 Daniel N. Schuhmann                    }
{                                                                              }
{ Original-NonVCL-Vorlage ==================================================== }
{                    Copyright (c) 2001 Michael Puff                           }
{                          www.luckie-online.de                                }
{                         mpuff@luckie-online.de                               }
{                                                                              }
{******************************************************************************}
program Dialog;

{$R res/icon.res}
{$R res/dialog.res}
{$R res/manifest.res}
{$R res/version.res}

{.$DEFINE CloseOnESC}    // Use this if you want to close on ESC-Key

uses
  Windows, Messages, MiniCommCtrl;

const
  IDC_CLOSE = 101;

{ GetLastError }
procedure DisplayErrorMsg(hWnd: THandle);
var
  szBuffer: array[0..255] of Char;
begin
  FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nil, GetLastError, 0, szBuffer,
    sizeof(szBuffer), nil);
  MessageBox(hWnd, szBuffer, 'Fehler', MB_ICONSTOP);
end;

function dlgfunc(hDlg: hWnd; uMsg: dword; wParam: wParam; lParam: lParam): bool;
  stdcall;
begin
  result := true;
  case uMsg of
    WM_INITDIALOG:
    begin
      SendMessage(hDlg, WM_SETICON, ICON_BIG, 
        Integer(LoadIcon(hInstance, MAKEINTRESOURCE(100))));
      LoadImage(hInstance, MAKEINTRESOURCE(100), IMAGE_ICON, 16, 16, 0);
    end;
    WM_CLOSE:
      PostQuitMessage(0);
    WM_COMMAND:
      {$IFDEF CloseOnESC}
      if(wParam = IDCANCEL) then SendMessage(hDlg,WM_CLOSE,0,0)
        else
        {$ENDIF}
        if HIWORD(wParam) = BN_CLICKED then
        begin
          case LoWord(wParam) of
            IDC_CLOSE:
              SendMessage(hDlg, WM_CLOSE, 0, 0);
          end;
        end;
    else
      result := false;
  end;
end;


var
  hDialog: THandle;
  msg: TMsg;

begin
  InitCommonControls;

  hDialog := CreateDialog(hInstance, MAKEINTRESOURCE(100), 0, @dlgfunc);  

  while GetMessage(msg,0,0,0) do
  begin
    IsDialogMessage(hDialog,msg);
  end;

  ExitCode := msg.wParam;

  DestroyWindow(hDialog);     
end.
